<?php
header("content-type:text/html;charset=utf-8");
$arrall=array();

function gettime($filename){
	global $arrall, $pcy,$pcm,$pcd,$pch,$pci,$pcs, $pmy,$pmm,$pmd,$pmh,$pmi,$pms, $pay,$pam,$pad,$pah,$pai,$pas;
	$c=filectime($filename);
	$ctime=date('Y-m-d H:i:s',$c);

	$m=filemtime($filename);
	$mtime=date('Y-m-d H:i:s',$m);

	$a=fileatime($filename);
	$atime=date('Y-m-d H:i:s',$a);
	
	echo "--》》创建时间：".$ctime." 修改时间：".$mtime." 访问时间：".$atime."<br>";
	$cy=substr($ctime, 0,4);
	$cm=substr($ctime, 5,2);
	$cd=substr($ctime, 8,2);
	$ch=substr($ctime, 11,2);
	$ci=substr($ctime, 14,2);
	$cs=substr($ctime, 17,2);
	
	$my=substr($mtime, 0,4);
	$mm=substr($mtime, 5,2);
	$md=substr($mtime, 8,2);
	$mh=substr($mtime, 11,2);
	$mi=substr($mtime, 14,2);
	$ms=substr($mtime, 17,2);
	
	$ay=substr($atime, 0,4);
	$am=substr($atime, 5,2);
	$ad=substr($atime, 8,2);
	$ah=substr($atime, 11,2);
	$ai=substr($atime, 14,2);
	$as=substr($atime, 17,2);
	if(($pcy===true||$pcy==$cy)&&($pcm===true||$pcm==$cm)&&($pcd===true||$pcd==$cd)&&($pch===true||$pch==$ch)&&($pci===true||$pci==$ci)&&($pcs===true||$pcs==$cs)
	&&($pmy===true||$pmy==$my)&&($pmm===true||$pmm==$mm)&&($pmd===true||$pmd==$md)&&($pmh===true||$pmh==$mh)&&($pmi===true||$pmi==$mi)&&($pms===true||$pms==$ms)
	&&($pay===true||$pay==$ay)&&($pam===true||$pam==$am)&&($pad===true||$pad==$ad)&&($pah===true||$pah==$ah)&&($pai===true||$pai==$ai)&&($pas===true||$pas==$as)){
		$arrall[] =$filename."--》》创建时间：".$ctime." 修改时间：".$mtime." 访问时间：".$atime."<br>";
	}
}
//preg('time_note.txt');
$row=$dir = $html = $htm = $php = $js = $css = $png = $jpg = $txt = $other = 0;

function getdir($path) {
	global $row,$dir , $html , $htm , $php , $js , $css , $png , $jpg , $txt , $other;
	$arr = scandir($path);
	foreach ($arr as $v) {
		if ($v != "." && $v != "..") {
			if (is_dir($path . "/" . $v)) {
				$row++;
				$dir++;
				echo "<hr>";
				echo $row."目录：" . $path . "/" . $v;
				echo "<br>";
				getdir($path . "/" . $v);
			} else {
				$row++;
				echo $row."文件：" . $path . "/" . $v;
				$ext = substr($v, (strrpos($v, ".") + 1));
				if ($ext == 'html' ) {
					$html++;
					gettime($path . "/" . $v);
				} elseif ($ext == 'htm') {
					$htm++;
					gettime($path . "/" . $v);
				} elseif ($ext == 'php') {
					$php++;
					gettime($path . "/" . $v);
				} elseif ($ext == 'js') {
					$js++;
					gettime($path . "/" . $v);
				} elseif ($ext == 'css') {
					$css++;
					gettime($path . "/" . $v);
				} elseif ($ext == 'png') {
					$png++;
					gettime($path . "/" . $v);
				} elseif ($ext == 'jpg') {
					$jpg++;
					gettime($path . "/" . $v);
				} elseif ($ext == 'txt') {
					$txt++;
					gettime($path . "/" . $v);
				} else {
					$other++;
					gettime($path . "/" . $v);
				}
				echo "<br>";
			}
		}
	}
}

$dirname = $_POST['webname'];
$pcy=$_POST['pcy']?$_POST['pcy']:TRUE;
$pcm=$_POST['pcm']?$_POST['pcm']:TRUE;
$pcd=$_POST['pcd']?$_POST['pcd']:TRUE;
$pch=$_POST['pch']?$_POST['pch']:TRUE;
$pci=$_POST['pci']?$_POST['pci']:TRUE;
$pcs=$_POST['pcs']?$_POST['pcs']:TRUE;
$ipcy=$pcy===TRUE?null:$pcy;
$ipcm=$pcm===TRUE?null:$pcm;
$ipcd=$pcd===TRUE?null:$pcd;
$ipch=$pch===TRUE?null:$pch;
$ipci=$pci===TRUE?null:$pci;
$ipcs=$pcs===TRUE?null:$pcs;

$pmy=$_POST['pmy']?$_POST['pmy']:TRUE;
$pmm=$_POST['pmm']?$_POST['pmm']:TRUE;
$pmd=$_POST['pmd']?$_POST['pmd']:TRUE;
$pmh=$_POST['pmh']?$_POST['pmh']:TRUE;
$pmi=$_POST['pmi']?$_POST['pmi']:TRUE;
$pms=$_POST['pms']?$_POST['pms']:TRUE;
$ipmy=$pmy===TRUE?null:$pmy;
$ipmm=$pmm===TRUE?null:$pmm;
$ipmd=$pmd===TRUE?null:$pmd;
$ipmh=$pmh===TRUE?null:$pmh;
$ipmi=$pmi===TRUE?null:$pmi;
$ipms=$pms===TRUE?null:$pms;

$pay=$_POST['pay']?$_POST['pay']:TRUE;
$pam=$_POST['pam']?$_POST['pam']:TRUE;
$pad=$_POST['pad']?$_POST['pad']:TRUE;
$pah=$_POST['pah']?$_POST['pah']:TRUE;
$pai=$_POST['pai']?$_POST['pai']:TRUE;
$pas=$_POST['pas']?$_POST['pas']:TRUE;
$ipay=$pay===TRUE?null:$pay;
$ipam=$pam===TRUE?null:$pam;
$ipad=$pad===TRUE?null:$pad;
$ipah=$pah===TRUE?null:$pah;
$ipai=$pai===TRUE?null:$pai;
$ipas=$pas===TRUE?null:$pas;

if (!empty($_POST['webname'])) {
	echo $dirname;
	echo "<hr>";
	getdir($dirname);

	echo "<hr><hr>";
	echo "本次匹配统计：递归文件夹" . $dir . "个！" ;
	echo "<br>";
	echo "遍历的文件总计:" . ($html+$htm+$php+$js+$css+$png+$jpg+$txt+$other) . "个!";
	echo "<br>";
	echo "其中：";
	echo "<br>";
	echo "遍历的HTML文件" . $html . "个!";
	echo "<br>";
	echo "遍历的htm模板" . $htm . "个!";
	echo "<br>";
	echo "遍历的PHP文件" . $php . "个!";
	echo "<br>";
	echo "遍历JS文件" . $js . "个!";
	echo "<br>";
	echo "遍历CSS文件" . $css . "个!";
	echo "<br>";
	echo "遍历png图片文件" . $png . "个!";
	echo "<br>";
	echo "遍历jpg图片文件" . $jpg . "个!";
	echo "<br>";
	echo "遍历txt文件" . $txt . "个!";
	echo "<br>";
	echo "遍历的其他文件" . $other . "个！<br>";
	echo "<hr>";
	echo "以下文件里有匹配的类容：";
	echo "<pre>";
	print_r($arrall);
	echo "</pre>";
	echo "匹配符合时间限制的文件：<br />";
	echo "本次成功匹配".count($arrall)."次！";
}
?>
<html>
	<head>
		<meta charset="utf-8">
		<title>查看文件时间</title>

		<style type="text/css">
.bai {
	width: 100%;
	height: 800px;
	background-color: white;
	position: absolute;
	z-index: 5;
	/*display: none;*/
}
#btn {
	cursor: default;
	color: white;
	margin-top: 300px;
}
			.small{
				width: 40px;
			}
		</style>
	</head>
	<body>
		<div class="bai" id="bai"><span id="btn">hehe</span></div>
		<form action="#" method="post">
			<br />
			<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;输入要查看的文件夹：
			<input type="text" name="webname" id="webname" value="<?php echo $dirname;?>" /> 
			<br />
			<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;文件创建时间做限制：
			<input class="small" type="text" name="pcy" value="<?php echo $ipcy;?>" />年
			<input class="small" type="text" name="pcm" value="<?php echo $ipcm;?>" />月
			<input class="small" type="text" name="pcd" value="<?php echo $ipcd;?>" />日
			<input class="small" type="text" name="pch" value="<?php echo $ipch;?>" />时
			<input class="small" type="text" name="pci" value="<?php echo $ipci;?>" />分
			<input class="small" type="text" name="pcs" value="<?php echo $ipcs;?>" />秒
			<br />
			<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;文件修改时间做限制：
			<input class="small" type="text" name="pmy" value="<?php echo $ipmy;?>" />年
			<input class="small" type="text" name="pmm" value="<?php echo $ipmm;?>" />月
			<input class="small" type="text" name="pmd" value="<?php echo $ipmd;?>" />日
			<input class="small" type="text" name="pmh" value="<?php echo $ipmh;?>" />时
			<input class="small" type="text" name="pmi" value="<?php echo $ipmi;?>" />分
			<input class="small" type="text" name="pms" value="<?php echo $ipms;?>" />秒
			<br />
			<br />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;文件访问时间做限制：
			<input class="small" type="text" name="pay" value="<?php echo $ipay;?>" />年
			<input class="small" type="text" name="pam" value="<?php echo $ipam;?>" />月
			<input class="small" type="text" name="pad" value="<?php echo $ipad;?>" />日
			<input class="small" type="text" name="pah" value="<?php echo $ipah;?>" />时
			<input class="small" type="text" name="pai" value="<?php echo $ipai;?>" />分
			<input class="small" type="text" name="pas" value="<?php echo $ipas;?>" />秒
			<br />
			<br />
			<input style="margin-left: 500px;margin-top: 12px;" type="submit" value="开始查看"/>
			<input style="margin-top: 12px;" type="reset" value="重置"/>
		</form>
		<br />
		<h3>注：输入本程序文件的相对目标文件夹</h3>
		<h3>注：日期时间不做限制的，留空</h3>
		<br />
		<br />
	</body>
<script type="text/javascript">
var btn=document.getElementById('btn');
var tag = 1;
btn.onclick = function(){
	var bai=document.getElementById('bai');
    if (tag == 1) {
        tag++;
    }else if(tag==8){
        alert(tag);
        bai.style.display="none";
        tag++;
    }else if(tag==999){
    	alert('999');
    	tag=1;
    }else{
    	tag++;
    }
}
</script>
</html>